package com.sbc.order.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sbc.common.toolkit.BeanUtil;
import com.sbc.order.dao.entity.TOrder;
import com.sbc.order.dao.entity.TOrderItem;
import com.sbc.order.dao.mapper.TOrderItemMapper;
import com.sbc.order.dao.mapper.TOrderMapper;
import com.sbc.order.pojo.vo.TicketOrderDetailRespVo;
import com.sbc.order.pojo.vo.TicketOrderItemDetailRespVo;
import com.sbc.order.service.ITOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author songbaicheng
 * @since 2024-05-11
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements ITOrderService {

    private final TOrderMapper orderMapper;
    private final TOrderItemMapper orderItemMapper;

    @Override
    public TicketOrderDetailRespVo queryTicketOrderByOrderSn(String orderSn) {
        LambdaQueryWrapper<TOrder> queryWrapper = Wrappers.lambdaQuery(TOrder.class)
                .eq(TOrder::getOrderSn, orderSn);
        TOrder orderDO = orderMapper.selectOne(queryWrapper);
        TicketOrderDetailRespVo result = BeanUtil.convert(orderDO, TicketOrderDetailRespVo.class);
        LambdaQueryWrapper<TOrderItem> orderItemQueryWrapper = Wrappers.lambdaQuery(TOrderItem.class)
                .eq(TOrderItem::getOrderSn, orderSn);
        List<TOrderItem> orderItemDOList = orderItemMapper.selectList(orderItemQueryWrapper);
        result.setOrderItemDetails(BeanUtil.convert(orderItemDOList, TicketOrderItemDetailRespVo.class));
        return result;
    }
}
